#ifndef MEASUREMENTCONTROLWIDGET_H
#define MEASUREMENTCONTROLWIDGET_H

#include <QWidget>
#include <QButtonGroup>
#include <QMap>
#include <QString>
#include <QVariant>
#include "MeasurementAlgorithmManager.h"
class QPushButton;
class MeasurementAlgorithmButton;

namespace Ui {
class MeasurementControlWidget;
}

class MeasurementControlWidget : public QWidget
{
    Q_OBJECT

public:
    explicit MeasurementControlWidget(MeasurementAlgorithmManager* pMeasurementAlgorithmManager,QWidget *parent = nullptr);
    ~MeasurementControlWidget();

    // 添加测量算法按钮
    void addMeasurementAlgorithmButton(const QString &algorithmName, const QString &iconPath = QString());

    // 启用/禁用所有算法按钮
    void enableAllAlgorithmButtons(bool enable);
    
    // 注册自定义测量工具widget，替换默认测量按钮
    void registerMeasurementToolWidget(QWidget* toolWidget);
    
    // 恢复默认测量按钮，清除注册的自定义工具
    void restoreDefaultMeasurementTools();
    
    // 根据算法名称设置测量按钮选中状态
    void setMeasurementAlgorithmButtonSelected(const QString& algorithmName, bool selected);

public slots:
    // 处理算法按钮点击事件
    void onAlgorithmButtonCheckedChange(bool checked);
    
    // 处理测量方式按钮点击事件
    void onMeasurementModeButtonChecked(bool checked);
signals:
    /**
     * @brief 发送测量图像请求信号
     * 当用户点击测量按钮时发出，通知插件执行相应的测量处理
     * @param measurementhmName 请求处理的算法名称
     * @param parameters 处理参数，默认空参数映射
     */
    void measurementImageRequested(const QString& measurementhmName, const QVariantMap& parameters = QVariantMap());
private:
    Ui::MeasurementControlWidget *ui;

    // 算法按钮映射表
    QMap<QString, MeasurementAlgorithmButton*> m_algorithmButtons;

    // 按钮组
    QButtonGroup *m_algorithmButtonGroup;
    QButtonGroup *m_shapeButtonGroup;
    MeasurementAlgorithmManager* m_pMeasurementAlgorithmManager;
    
    // 存储注册的自定义测量工具widget
    QWidget* m_registeredToolWidget;
    
    // 测量按钮ID枚举
    enum ButtonId {
        Horizontal = 0,
        Vertical,
        Rectangle
    };
};

#endif // MEASUREMENTCONTROLWIDGET_H
